<template>
  <div>
    登录
    <van-button type="primary" @click="goHome">Button</van-button>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  components: {},
  data() {
    return {}
  },
  computed: {
    ...mapGetters(['getNativeApi', 'getNativeCallJs'])
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      vm.getNativeCallJs.registerNativieGoBack(() => {
        vm.goBack()
      })
    })
  },
  created() {},
  methods: {
    goBack() {
      this.$toast({
        message: '再次滑动退出app'
      })
      if (!this.first) {
        this.first = Date.now()
        setTimeout(() => {
          this.first = 0
        }, 1000)
      } else {
        if (Date.now() - this.first < 1000) {
          this.getNativeApi.closeApp()
          console.log('退出登录')
          this.first = 0
        }
      }
    },

    goHome() {
      this.$router.replace({ name: 'home' })
    }
  }
}
</script>

<style lang="scss" scoped>
.font-18 {
  font-size: 18px;
}
</style>
